package toman;

import org.apache.derby.jdbc.ClientDataSource40;

import java.sql.SQLException;
import java.util.Calendar;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: zslajchrt
 * Date: 2.5.11
 * Time: 16:49
 * To change this template use File | Settings | File Templates.
 */
public class Main {

    public static void main(String[] args) throws SQLException {

        // TOMan initialization - should be done in EJB or Spring, for example

        ClientDataSource40 ds = new ClientDataSource40();
        ds.setServerName("localhost");
        ds.setDatabaseName("sun-appserv-samples");
        ds.setUser("APP");
        ds.setPassword("APP");

        QueryEngineSelectorImpl engineSelector = new QueryEngineSelectorImpl();
        engineSelector.addEngine(new PhotoFilterEngine(ds));

        TOManImpl toMan = new TOManImpl(engineSelector);

        // TOMan usage

        PhotoFilter filter = new PhotoFilter();
        filter.setName("p1");
        Calendar cal = Calendar.getInstance();
        cal.set(2011, 3, 22);
        filter.setCreated(new java.sql.Date(cal.getTimeInMillis()));

        TOQuery<SimplePhotoTO> query = toMan.createQuery(SimplePhotoTO.class, filter);

        List<SimplePhotoTO> results = query.getResults();

        for (SimplePhotoTO photoTO : results) {
            System.out.println(photoTO);
        }
    }
}
